import car.Cars;
import operation.DBHelper;
import operation.Exit;
import user.AdminUser;
import user.NormalUser;
import user.User;


import java.sql.SQLException;
import java.util.Scanner;

public class Main {

    public static User login() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你的名字：");
        String name = scanner.nextLine();
        System.out.println("请选择你的身份：1->管理员  0->普通用户");
        int choice = scanner.nextInt();


        if (choice == 1) {
            return new AdminUser(name);
        } else {
            return new NormalUser(name);
        }
    }

    public static void main(String[] args) throws SQLException {
        Cars cars = new Cars();
        User user = login();
        Exit exit = new Exit();
        boolean flag = exit.isFlag();
        while (!flag) {
            int choice = user.menu();
            user.doOperation(choice, cars);
            flag = exit.isFlag();
        }
        DBHelper.closeConnection(DBHelper.getConnection());
    }
}
